The Find and Replace Dialog


The Find and Replace Dialog

It is a standard dialog that allows the user to find and replace text in an application. As the dialog is open while the user works on the Main Window, it is a modeless dialog.
Es un diálogo estándar que permite al usuario encontrar y reemplazar texto en una aplicación. Debido a que el diálogo está abierto mientras el usuario trabaja en la Ventana Principal, es diálogo es una un Diálogo Modeless.

Tip
The use of standard dialogs will reduce the time that the user will require to learn an application or program.
El uso de diálogos estándar reducirá el tiempo que usuario tarda en aprender una aplicación o programa.

Problem 1
Create a Window Application using Wintempla called TextWindow to test the Find and Replace dialog. Insert a textbox and two buttons as shown. Set the textbox properties as shown below. Use Wintempla to add the WndProc event in the Main Window.
Cree una Aplicación de Ventana usando Wintempla llamada TextWindow para probar el diálogo de Buscar y Encontrar. Inserte una caja de texto y dos botones como se muestra. Fije las propiedades de la caja de texto como se muestra. Use Wintempla para agregar el evento WndProc en la Ventana Principal.

TextboxProperties

TextWindowRun

TextWindow.h
#pragma once //______________________________________ TextWindow.h
#include "Resource.h"
class TextWindow: public Win::Window
{
public:
     TextWindow()
     {
     }
     ~TextWindow()
     {
     }
     Win::FindReplaceDlg findReplaceDlg;
     ...
};


TextWindow.cpp
#include "stdafx.h" //________________________________________ TextWindow.cpp
#include "TextWindow.h"

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR cmdLine, int cmdShow){
     TextWindow app;
     app.CreateMainWindow(L"TextWindow", cmdShow, IDI_TextWindow, NULL, (HBRUSH)(COLOR_WINDOW + 1), hInstance);
     //_______________________________________________ BE SURE TO EDIT THE FOLLOWING LINE
     return app.MessageLoop(IDC_TextWindow, app.findReplaceDlg);
}

void TextWindow::Window_Open(Win::Event& e)
{
}

void TextWindow::btFind_Click(Win::Event& e)
{
     findReplaceDlg.Flags = FR_HIDEUPDOWN;
     findReplaceDlg.BeginFindDialog(hWnd, L"Hello");
}

void TextWindow::btReplace_Click(Win::Event& e)
{
     findReplaceDlg.Flags = FR_HIDEUPDOWN;
     findReplaceDlg.BeginReplaceDialog(hWnd, L"Hello", L"Hola");
}

bool TextWindow::Window_WndProc(Win::Event& e)
{
     if (findReplaceDlg.IsEvent(e))
     {
          LPFINDREPLACE pFindReplace = (LPFINDREPLACE)e.lParam;
          const bool matchWholeWord = ((pFindReplace->Flags & FR_WHOLEWORD) != 0);
          const bool matchCase = ((pFindReplace->Flags & FR_MATCHCASE) != 0);
          if (pFindReplace->Flags & FR_REPLACE)
          {
               if (tbxInput.ReplaceNext(pFindReplace->lpstrFindWhat, pFindReplace->lpstrReplaceWith, matchWholeWord, matchCase) < 0)
               {
                    this->MessageBox(L"The end of the text has been reached", L"TextWindow", MB_OK | MB_ICONINFORMATION);
               }
          }
          else if (pFindReplace->Flags & FR_REPLACEALL)
          {
               const int count = tbxInput.ReplaceAll(pFindReplace->lpstrFindWhat, pFindReplace->lpstrReplaceWith, matchWholeWord, matchCase);
               wchar_t text[64];
               _snwprintf_s(text, 64, _TRUNCATE, L"%d replacements were done", count);
               this->MessageBox(text, L"TextWindow", MB_OK | MB_ICONINFORMATION);
          }
          else if (pFindReplace->Flags & FR_FINDNEXT)
          {
               if (tbxInput.FindNext(pFindReplace->lpstrFindWhat, matchWholeWord, matchCase) < 0)
               {
                    this->MessageBox(L"The end of the text has been reached", L"TextWindow", MB_OK | MB_ICONINFORMATION);
               }
          }
          return true;
     }
     e.returnValue = FALSE;
     return false;
}

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home